<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['worker']=$this->model('model')->checkworker();
if($_RQ['op']=='main'){
	$return['ischecklogin']=model('jy_weishop/member')->checklogin('','','','',true);
	$status=intval($_RQ['status']);
	$return['list']=array();
	$return['params']=array('status'=>$status);
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$lastdaytime = $daytime-24*3600;
	$data['inall0']=pdo_getsum('jy_yxgz_orderlog',array('status'=>0,'workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid']),'price');
	$data['inall']=pdo_getsum('jy_yxgz_orderlog',array('status'=>1,'workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid']),'price');
	$data['inday']=pdo_getsum('jy_yxgz_orderlog',array('status'=>1,'workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid'],'pay_time >'=>$daytime),'price');
	$data['inlastday']=pdo_getsum('jy_yxgz_orderlog',array('status'=>1,'workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid'],'pay_time between'=>array($lastdaytime,$daytime)),'price');
	$data['beninall']=pdo_getsum('jy_yxgz_orderlog',array('status'=>1,'workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid']),'benprice');
	$data['beninday']=pdo_getsum('jy_yxgz_orderlog',array('status'=>1,'workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid'],'pay_time >'=>$daytime),'benprice');
	$data['beninlastday']=pdo_getsum('jy_yxgz_orderlog',array('status'=>1,'workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid'],'pay_time between'=>array($lastdaytime,$daytime)),'benprice');
	$monthtime = mktime(0,0,0,date('m'),1,date('Y'));
	$data['monthinall']=pdo_getsum('jy_yxgz_orderlog',array('status'=>1,'workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid'],'pay_time >'=>$daytime),'price');
	foreach($data as &$row){
		$row=price($row);
	}
	$return['data']=$data;
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
	$return['member']=$member;
	$return['psize']=20;
	set_html('title','业绩明细');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['status']!=10){
		$params['status']=$_RQ['status'];
	}
	if($this->setting['is_orderlog']){
		$month = date('Y-m',strtotime('-1 month'));
		$kantime=strtotime($month);
	}
	if($_RQ['tstart']){
		$tstart=strtotime($_RQ['tstart']);
	}else{
		$tstart=$_RQ['newtstart']?:0;
	}
	if($kantime && $tstart<$kantime){
		$tstart=$kantime;
	}
	if($_RQ['tend']){
		$tend=strtotime($_RQ['tend']);
	}else{
		$tend=$_RQ['newtend']?:TIMESTAMP;
	}
	if($_RQ['keyword']){
		if(intval($_RQ['keyword'])){
			$params['mobile like']='%'.trim($_RQ['keyword']).'%';
		}else{
			$params['username like']='%'.trim($_RQ['keyword']).'%';
		}
		$return['params']['keyword']=$_RQ['keyword'];
	}
	$params['createtime between']=array($tstart,$tend);
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=pdo_getlist('jy_yxgz_orderlog',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['statustitle']=$this->orderlog_status[$item['status']];	
		$item['goodsinfo']=json_decode($item['goodsinfo'],true);
		$item['payimgs']=array($item['payimg']);
		$item['pay_time']=date('Y-m-d H:i',$item['pay_time']);
		$item['createtime']=date('Y-m-d H:i',$item['createtime']);
	}
	exi($list);
}
?>